package com.yami.shop.api.controller;


import com.yami.shop.bean.dto.FlowLogDto;
import com.yami.shop.bean.model.FlowLog;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.security.api.model.YamiUser;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.FlowLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.yami.shop.common.util.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;


/**
 * 用户流量记录
 *
 * @author YXF
 * @date 2020-07-13 13:18:33
 */
@RestController
@RequestMapping("/p/flowAnalysisLog")
@Tag(name = "用户流量记录接口")
public class FlowLogLoginController {

    @Autowired
    private FlowLogService flowLogService;



    @PostMapping
    @Operation(summary =  "新增用户流量记录")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid FlowLogDto flowLogDto, HttpServletRequest request) {
        FlowLog flowLog = BeanUtil.map(flowLogDto, FlowLog.class);
        YamiUser user = SecurityUtils.getUser();
        flowLog.setUserId(user.getUserId());
        flowLogService.saveUserFlowLog(flowLog, request);
        return ServerResponseEntity.success();
    }
}
